package 创建型设计模式.原型模式.demo;

/**
 * 利用序列化模式实现的深拷贝
 * @Author lf
 * @Date 3/30/2024
 */
public class DeepCopyDemo {
    public static void main(String[] args) {
        DeepB deepB = new DeepB();
        deepB.setName("deepB");

        DeepA deepA = new DeepA();
        deepA.setName("deepA");
        deepA.setDeepB(deepB);

        DeepA deepA1 = DeepCopyViaSerialization.deepCopy(deepA);

        System.out.println(deepA1 == deepA);
        System.out.println(deepA1.getDeepB() == deepA.getDeepB());


        DeepA deepA2 = DeepCopyViaJsonWithTypeRef.deepCopy(deepA,DeepA.class);
        System.out.println(deepA2 == deepA);
        System.out.println(deepA2.getDeepB() == deepA.getDeepB());
    }
}
